package com.yellowpage.omc.ability.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.omc.ability.data.AppInterfaceParam;
import com.yellowpage.omc.ability.dao.AppInterfaceParamDao;

public class AppInterfaceParamServiceImpl extends BaseServiceImpl implements AppInterfaceParamService {
	  private AppInterfaceParamDao appInterfaceParamDao;
	
	  public void setAppInterfaceParamDao(AppInterfaceParamDao appInterfaceParamDao) {
		  this.appInterfaceParamDao = appInterfaceParamDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public AppInterfaceParam getAppInterfaceParam(Long id){
	      return appInterfaceParamDao.get(id);
	  }
	  
    public List<AppInterfaceParam> getAllAppInterfaceParam(){
        return appInterfaceParamDao.getAll();
    }
    
    public List<Map> queryAppInterfaceParamByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT d.NAME as INTERFACE_NAME, a.INTERFACE_PARAM_ID , a.INTERFACE_ID , a.PARAM_KEY , a.PARAM_NAME , a.NOTE , " +
				"       (select display_name from CA_USER where user_id = a.LAST_UPDATE_USER) as last_update_user, " +
				"       (select display_name from CA_USER where user_id = a.CREATE_USER) as create_user, " +
				"         a.CREATE_TIME , a.LAST_UPDATE_TIME , a.TYPE , a.STATUS , (SELECT display_name FROM CA_USER WHERE user_id = a.LAST_SYNCHRONIZATION_USER) AS last_synchronization_user,a.LAST_SYNCHRONIZATION_TIME" +
				"  FROM OMC_INTERFACE_PARAM a,  OMC_INTERFACE d " +
				" WHERE a.INTERFACE_ID = d.INTERFACE_ID ")
				    			.addCondition(" and INTERFACE_PARAM_ID = :interfaceParamId ")
							    			.addCondition(" and a.INTERFACE_ID = :interfaceId ")
							    			.addCondition(" and PARAM_KEY = :paramKey ")
							    			.addCondition(" and PARAM_NAME = :paramName ")
							    			.addCondition(" and NOTE = :note ")
							    			.addCondition(" and CREATE_USER = :createUser ")
							    		    .addCondition(" and date_format(CREATE_TIME,'%Y-%m-%d') =  :createTime  ")
		    				    			.addCondition(" and LAST_UPDATE_USER = :lastUpdateUser ")
							    		    .addCondition(" and date_format(LAST_UPDATE_TIME,'%Y-%m-%d') =  :lastUpdateTime  ")
		    				    			.addCondition(" and a.TYPE = :type ")
							    			.addCondition(" and a.STATUS = :status ")
							    			.addCondition(" and LAST_SYNCHRONIZATION_USER = :LastSynchronizationUser ")
							    			.addCondition(" and LAST_SYNCHRONIZATION_TIME = :LastSynchronizationTime "); 		    
		    

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveAppInterfaceParam(AppInterfaceParam appInterfaceParam){
        appInterfaceParamDao.save(appInterfaceParam);
    }
    
	  public void updateAppInterfaceParam(AppInterfaceParam appInterfaceParam){
	      appInterfaceParamDao.update(appInterfaceParam);
	  }
	  
	  public void delete(List deleteList){
	      appInterfaceParamDao.remove(deleteList);
	  }
	  
	  
	 
	
}	